package team.knowers.qzh.qzhserver.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import team.knowers.qzh.qzhserver.dao.entity.CourseContentDO;
import team.knowers.qzh.qzhserver.dao.mapper.CourseContentMapper;
import team.knowers.qzh.qzhserver.dto.resp.CourseContentDetailsRespDTO;
import team.knowers.qzh.qzhserver.service.CourseContentService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wutai
 */
@Service
@RequiredArgsConstructor
public class CourseContentServiceImpl extends ServiceImpl<CourseContentMapper, CourseContentDO> implements CourseContentService {
    @Override
    public List<CourseContentDetailsRespDTO> getCourseContentDetailsById(Long id) {
        LambdaQueryWrapper<CourseContentDO> queryWrapper = Wrappers.lambdaQuery(CourseContentDO.class)
                .eq(CourseContentDO::getSectionId, id)
                .eq(CourseContentDO::getDelFlag, 0)
                .orderByAsc(CourseContentDO::getOrder);
        List<CourseContentDO> courseContentDO = baseMapper.selectList(queryWrapper);

        List<CourseContentDetailsRespDTO> results =  new ArrayList<>();
        for (CourseContentDO courseContentDO1 : courseContentDO) {
            results.add(BeanUtil.toBean(courseContentDO1, CourseContentDetailsRespDTO.class));
        }
        return results;
    }
}
